package com.example.fw;

import java.util.ArrayList;
import java.util.List;

import org.netbeans.jemmy.operators.JDialogOperator;
import org.netbeans.jemmy.operators.JTreeOperator;

import com.example.tests.Folders;

public class FolderHelper extends HelpersBase{
	
	public FolderHelper(ApplicationManager applicationManager) {
		super(applicationManager);
	}

	public Folders getFolders() {
		List<String> list = new ArrayList<String>();
	    JTreeOperator tree = new JTreeOperator(mainFrame);
	    Object[] children = tree.getChildren(tree.getRoot());
		for (Object child : children){
			list.add("" + child);	
		}
		return new Folders(list);
	}

	public String createFolder(String foldername) {
		manager.getMenuHelper().clickMenuItem("File|New folder...");
		JDialogOperator dialog = new JDialogOperator(mainFrame);
		manager.getDialogHelper()
		.setTextInDialog(foldername, dialog)
		.clickButtonInDialog(dialog, "OK");
		return waitMessageDialog("Warning", 3000);
	}



	public void deleteFolder(String folder) {
		if (manager.getTreeHelper().clickTreeItem(folder) != null){
			manager.getMenuHelper().clickMenuItem("File|Delete");
			JDialogOperator dialog = new JDialogOperator(mainFrame);
			manager.getDialogHelper().clickButtonInDialog(dialog, "Yes");
		}
	}


}
